
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="xms">
    <meta name="author" content="xms">
    <link rel="icon" href="/content/favicon.ico">

    <title>自定义 - 实体 - 字段 - 新建</title>

    <!-- Bootstrap core CSS -->
    <link href="/content/css/bootstrap3.3.5/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="/content/css/dashboard.css" rel="stylesheet">
    <link href="/content/css/font-awesome.min.css" rel="stylesheet">
    <link href="/content/customize/css/common.css" rel="stylesheet">
    <link href="/content/js/jquery-toast/jquery.toast.min.css" rel="stylesheet">
    <link id="themeLink" href="/content/css/theme/default.css" rel="stylesheet" />
    <!-- Bootstrap core JavaScript ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="/content/js/jquery.min.js"></script>
    <script src="/content/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="/content/js/ie10-viewport-bug-workaround.js"></script>
    <script src="/content/js/jquery.bootstrap.min.js"></script>
    <script src="/content/js/json2.js"></script>
    <script src="/content/js/xms.utility.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.core.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.widget.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
    <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
    <script src="/content/js/jquery-toast/jquery.toast.min.js"></script>
    <script src="/content/js/xms.jquery.js"></script>
    <script src="/content/js/xms.web.js"></script>
    <script src="/content/js/xms.metadata.js"></script>
    <script src="/content/js/md5.js" type="text/javascript"></script>
    <script src="/content/js/commonlabels.js"></script>
    <script src="/content/js/common/pagecontext.js"></script>
    <script src="/api/user/usercontext"></script>
    <script>
        jQuery(function () {
            Xms.Web.Loading();
            function aLinkClick(e) {

                if (currentKeycode != 17 && window.parent && window.parent.addToTab) {
                    e.preventDefault();
                    var tabNav = $('#customTabNav', parent.document).children('.iframe-link-linkitem.active');
                    var textEl = tabNav.clone();
                    $(".glyphicon-remove", textEl).remove();
                    var label = textEl.text();
                    textEl = $(this).clone();
                    $("span", textEl).remove();
                    label = label + '-' + textEl.text();
                    var link = $(this).attr("href");
                    var id = $.md5(link);
                    Xms.Web.callParentMethod('addToTab', { id: id, label: label, link: link });
                    return false;
                } else {
                    //  currentKeycode = -99999;
                    //  var link = $(this).attr("href");
                    //  Xms.Web.OpenWindow(link);
                }

            }
            var currentKeycode = -99999;
            $("body").on("click.customizeLinkclick", 'a[href]a:not([href^="javascript:"])a:not([href^="#"])', function (e) {
                aLinkClick.call(this, e);
            });
        });
    </script>
    <style>
        body {
            padding: 0;
            margin: 0;
        }

        .table-responsive {
            max-height: 400px;
            overflow-y: auto;
        }

        .panel-default .panel-heading {
            background-color: white;
        }
    </style>
</head>
<body>
<div class="" id="body">
    <div class="clearfix">
        <div class="col-md-12" id="main">
            <div class="" style="padding:5px;" id="renderBody">
                <!--main-->

                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <a data-toggle="collapse"
                               href="#collapseTwo">
                                <strong>新建字段</strong>
                            </a>
                        </h3>
                    </div>
                    <div id="collapseTwo" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <form action="/xms/api/schema/attribute/create" method="post" data-jsonajax="true" data-formdata="false" id="createattributeForm" class="form-horizontal" role="form" data-autoreset="true">
                                <input data-val="true" id="entityid" name="entityid" type="hidden" />
                                <input id="SummaryExpression" name="SummaryExpression" type="hidden" value="" />
                                <input id="FormulaExpression" name="FormulaExpression" type="hidden" value="" />
                                <input type="hidden" id="filterConditions" value="" />
                                <input type="hidden" id="valueSetJson" value="" />
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="Name">名称</label>
                                    <div class="col-sm-10">
                                        <input autofocus="true" class="form-control required" data-custom="validName" data-customMsg="首字符为字母，只能输入数字，字母或者下划线" data-customReg="^[a-zA-Z]&#x2B;[\w_]*$" data-val="true" data-val-length="The field Name must be a string with a maximum length of 50." data-val-length-max="50" data-val-required="The Name field is required." id="Name" maxlength="50" name="name" type="text" validName="True" value="" />
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="LocalizedName">显示标签</label>
                                    <div class="col-sm-10">
                                        <input class="form-control required" data-val="true" data-val-required="The LocalizedName field is required." id="LocalizedName" name="localizedName" type="text" value="" />
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="IsRequired1">必填</label>
                                    <div class="col-sm-10">
                                        <label class="checkbox-inline">
                                            <input class="required" data-val="true" data-val-required="The IsRequired field is required." id="IsRequired1" name="isrequired" type="radio" value="true" /> 是
                                        </label>
                                        <label class="checkbox-inline">
                                            <input checked="checked" class="required" id="IsRequired0" name="isrequired" type="radio" value="false" /> 否
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="LogEnabled1">日志监控</label>
                                    <div class="col-sm-10">
                                        <label class="checkbox-inline">
                                            <input class="required" data-val="true" data-val-required="The LogEnabled field is required." id="LogEnabled1" name="logenabled" type="radio" value="True" /> 启用
                                        </label>
                                        <label class="checkbox-inline">
                                            <input checked="checked" class="required" id="LogEnabled0" name="logenabled" type="radio" value="false" /> 禁用
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="AuthorizationEnabled1">权限控制</label>
                                    <div class="col-sm-10">
                                        <label class="checkbox-inline">
                                            <input class="required" data-val="true" data-val-required="required" id="AuthorizationEnabled1" name="authorizationenabled" type="radio" value="true" /> 启用
                                        </label>
                                        <label class="checkbox-inline">
                                            <input checked="checked" class="required" id="AuthorizationEnabled0" name="authorizationenabled" type="radio" value="false" /> 禁用
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="Description">描述</label>
                                    <div class="col-sm-10">
                        <textarea class="form-control" id="Description" name="description" row="5"></textarea>
                                    </div>
                                </div>
                                <div class="form-group col-sm-12">
                                    <label class="col-sm-2 control-label" for="attributetypename">类型</label>
                                    <div class="col-sm-10">
                                        <select name="attributetypename" id="attributetypename" class="form-control required">
                                            <option value="">请选择</option>
                                            <option value="nvarchar">文本</option>
                                            <option value="ntext">大文本</option>
                                            <option value="int">整数</option>
                                            <option value="float">浮点数</option>
                                            <option value="money">金额</option>
                                            <option value="picklist">选项集</option>
                                            <option value="bit">是/否</option>
                                            <option value="datetime">日期时间</option>
                                            <option value="lookup">引用</option>
                                            <option value="uniqueidentifier">全局唯一码</option>
                                        </select>
                                    </div>
                                </div>
                                <div id="settings">
                                    <div class="hide" id="nvarcharSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="nvarchar-format">格式</label>
                                            <div class="col-sm-10">
                                                <select name="textformat" id="nvarchar-format" class="form-control">
                                                    <option value="text">无限制</option>
                                                    <option value="email">电子邮件</option>
                                                    <option value="url">链接</option>
                                                    <option value="unlink">文本</option>
                                                    <option value="password">密码</option>
                                                    <option value="textarea">多行文本</option>
                                                    <option value="fileupload">文件上传</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="nvarchar-length">最大长度</label>
                                            <div class="col-sm-10">
                                                <input name="maxlength" id="nvarchar-length" value="50" class="form-control input-sm" data-type="int" data-range="[10,4000]" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="ntextSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="ntext-format">格式</label>
                                            <div class="col-sm-10">
                                                <select name="ntextformat" id="ntext-format" class="form-control">
                                                    <option value="text">无限制</option>
                                                    <option value="email">富文本</option>
                                                    <option value="fileupload">文件上传</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="intSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="int-minvalue">最小值</label>
                                            <div class="col-sm-10"><input name="intminvalue" id="int-minvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="0" /></div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="int-maxvalue">最大值</label>
                                            <div class="col-sm-10"><input name="intmaxvalue" id="int-maxvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="2147483647" /></div>
                                        </div>
                                    </div>
                                    <div class="hide" id="floatSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="float-precision">小数位数</label>
                                            <div class="col-sm-10">
                                                <input name="floatprecision" id="float-precision" class="form-control input-sm" value="2" data-range="[0,8]" />
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="float-minvalue">最小值</label>
                                            <div class="col-sm-10">
                                                <input name="floatminvalue" id="float-minvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="0" />
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="float-maxvalue">最大值</label>
                                            <div class="col-sm-10">
                                                <input name="floatmaxvalue" id="float-maxvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="2147483647" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="moneySetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="money-precision">小数位数</label>
                                            <div class="col-sm-10">
                                                <input name="moneyprecision" id="money-precision" class="form-control input-sm" value="2" data-range="[0,8]" />
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="money-minvalue">最小值</label>
                                            <div class="col-sm-10">
                                                <input name="moneyminvalue" id="money-minvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="0" />
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="money-maxvalue">最大值</label>
                                            <div class="col-sm-10">
                                                <input name="moneymaxvalue" id="money-maxvalue" class="form-control input-sm" data-range="[-2147483648,2147483647]" value="2147483647" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="picklistSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="optionset-type">格式</label>
                                            <div class="col-sm-10">
                                                <select name="optionsettype" id="optionset-type" class="form-control">
                                                    <option value="select">下拉</option>
                                                    <option value="radio">单选</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="optionset-picklist">选项</label>
                                            <div class="col-sm-10">
                                                <label class="control-label"><input type="checkbox" value="true" name="iscommonoptionset" onclick="selectOptionset(this)" />选择现有选项集</label>
                                                <div id="optionset-commonarea" class="input-group hide col-sm-12">
                                                    <select name="commonoptionset" id="optionset-common" class="form-control input-sm"></select>
                                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default btn-sm" onclick="loadOptionSet()" title="刷新">
                                            <span class="glyphicon glyphicon-refresh"></span>
                                        </button>
                                        <button type="button" class="btn btn-primary btn-sm" onclick="Xms.Web.OpenWindow(ORG_SERVERURL+'/customize/optionset/createoptionset?solutionid=0d3754d8-05b9-41ce-9ae0-83125fd79c27')">
                                            <span class="glyphicon glyphicon-plus-sign"></span> 新建
                                        </button>
                                    </span>
                                                </div>
                                                <div id="optionset-privatearea">
                                                    <div class="btn-group">
                                                        <button type="button" class="btn btn-primary btn-xs" onclick="addOption('optionset-picklist')">
                                                            <span class="glyphicon glyphicon-plus-sign"></span> 增加
                                                        </button>
                                                        <button type="button" class="btn btn-default btn-xs" onclick="clearOption('optionset-picklist')">
                                                            <span class="glyphicon glyphicon-trash"></span> 清空
                                                        </button>
                                                    </div>
                                                    <table id="optionset-picklist" class="table">
                                                        <thead>
                                                        <tr>
                                                            <th>名称</th>
                                                            <th>值</th>
                                                            <th>默认选中</th>
                                                            <th>操作</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        <tr>
                                                            <td><input onblur="CheckRepeat('optionsetname')" type="text" class="form-control input-sm optionsetname" name="optionsetname" maxlength="200" value="名称" /></td>
                                                            <td><input onblur="CheckRepeat('optionsetvalue')" type="text" class="form-control input-sm optionsetvalue" name="optionsetvalue" value="0" data-range="[-2147483648,2147483648]" /></td>
                                                            <td>
                                                                <input type="checkbox" name="optionListChecker" onclick="$(this).next().val($(this).prop('checked'))" />
                                                                <input name="isselectedoption" type="hidden" value="false" />
                                                            </td>
                                                            <td>
                                                                <button type="button" class="btn btn-warning btn-xs" onclick="removeOption('optionset-picklist', this)">
                                                                    <span class="glyphicon glyphicon-trash"></span>
                                                                </button>
                                                                <button type="button" class="btn btn-info btn-xs" onclick="moveOption('optionset-picklist', this, true)">
                                                                    <span class="glyphicon glyphicon-arrow-up"></span>
                                                                </button>
                                                                <button type="button" class="btn btn-info btn-xs" onclick="moveOption('optionset-picklist', this, false)">
                                                                    <span class="glyphicon glyphicon-arrow-down"></span>
                                                                </button>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><input onblur="CheckRepeat('optionsetname')" type="text" class="form-control input-sm optionsetname" name="optionsetname" maxlength="200" value="名称1" /></td>
                                                            <td><input onblur="CheckRepeat('optionsetvalue')" type="text" class="form-control input-sm optionsetvalue" name="optionsetvalue" value="1" data-range="[-2147483648,2147483648]" /></td>
                                                            <td>
                                                                <input type="checkbox" name="optionListChecker" onclick="$(this).next().val($(this).prop('checked'))" />
                                                                <input name="isselectedoption" type="hidden" value="false" />
                                                            </td>
                                                            <td>
                                                                <button type="button" class="btn btn-warning btn-xs" onclick="removeOption('optionset-picklist', this)">
                                                                    <span class="glyphicon glyphicon-trash"></span>
                                                                </button>
                                                                <button type="button" class="btn btn-info btn-xs" onclick="moveOption('optionset-picklist', this, true)">
                                                                    <span class="glyphicon glyphicon-arrow-up"></span>
                                                                </button>
                                                                <button type="button" class="btn btn-info btn-xs" onclick="moveOption('optionset-picklist', this, false)">
                                                                    <span class="glyphicon glyphicon-arrow-down"></span>
                                                                </button>
                                                            </td>
                                                        </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="bitSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label">选项</label>
                                            <div class="col-sm-10">
                                                <table class="table">
                                                    <thead>
                                                    <tr>
                                                        <th>名称</th>
                                                        <th>默认选中</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <tr>
                                                        <td>True：<input type="text" class="form-control input-sm" name="bitoptionname" value="是" maxlength="200" /></td>
                                                        <td>
                                                            <input type="checkbox" name="bitisdefault" value="true" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>False：<input type="text" class="form-control input-sm" name="bitoptionname" value="否" maxlength="200" /></td>
                                                        <td>
                                                            <input type="checkbox" name="bitisdefault" value="false" />
                                                        </td>
                                                    </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="datetimeSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="datetime-format">格式</label>
                                            <div class="col-sm-10">
                                                <select name="datetimeformat" id="datetime-format" class="form-control">
                                                    <option value="yyyy/MM/dd">仅日期(yyyy/MM/dd)</option>
                                                    <option value="yyyy/MM/dd hh:mm:ss">日期和时间(yyyy/MM/dd hh:mm:ss)</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hide" id="lookupSetting">
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="lookup-entity">相关实体</label>
                                            <div class="col-sm-10">
                                                <input name="lookupentity" id="lookup-entity" class="form-control" />
                                            </div>
                                        </div>
                                        <div class="form-group col-sm-12">
                                            <label class="col-sm-2 control-label" for="lookup-type">格式</label>
                                            <div class="col-sm-10">
                                                <select name="lookuptype" id="lookup-type" class="form-control">
                                                    <option value="link">链接</option>
                                                    <option value="unlink">文本</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="hide" id="partylistSetting">
                                    <div class="form-group col-sm-12">
                                        <label class="col-sm-2 control-label" for="partylist-format">格式</label>
                                        <div class="col-sm-10">
                                            <select name="partylistformat" id="partylist-format" class="form-control">
                                                <option value="checkbox">复选框</option>
                                                <option value="lookup">查找框</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <fieldset class="col-sm-12 hide" id="valueSetting">
                                    <legend>值设置</legend>
                                    <div class="form-group col-sm-12">
                                        <label class="col-sm-2 control-label" for="valuetype">来源</label>
                                        <div class="col-sm-10">
                                            <select class="form-control" name="valuetype" id="valuetype">
                                                <option value="0">无</option>
                                                <option value="1">默认值</option>
                                                <option value="2">计算公式</option>
                                                <option value="3">累计汇总</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div id="valueSection">
                                        <div class="hide" id="defaultSection">
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" id="defaultvalue">输入值</label>
                                                <div class="col-sm-10">
                                                    <textarea class="form-control" name="defaultvalue"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hide" id="summarySection">
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="int-minvalue">汇总对象</label>
                                                <div class="col-sm-10">
                                                    <select class="form-control" name="summaryentityid" id="summaryentityid"></select>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="summarytype">运算类型</label>
                                                <div class="col-sm-4">
                                                    <select class="form-control" name="summarytype" id="summarytype">
                                                        <option>计数</option>
                                                        <option>合计</option>
                                                        <option>最大值</option>
                                                        <option>最小值</option>
                                                    </select>
                                                </div>
                                                <label class="col-sm-2 control-label" for="summaryfield">运算字段</label>
                                                <div class="col-sm-4">
                                                    <select class="form-control" name="summaryfield" id="summaryfield"></select>
                                                </div>
                                            </div>
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label" for="summaryfiltertype">过滤条件</label>
                                                <div class="col-sm-10">
                                                    <label class="checkbox-inline"><input type="radio" name="summaryfiltertype" id="summaryfiltertype" value="1" checked />包含所有记录</label>
                                                    <label class="checkbox-inline"><input type="radio" name="summaryfiltertype" id="summaryfiltertype" value="2" />指定条件记录</label>
                                                </div>
                                                <div class="col-sm-10 col-sm-offset-2 hide" id="filterSection">
                                                    <table class="table">
                                                        <thead><tr><th>字段</th><th>运算符</th><th>值</th><th class="col-sm-4"></th></tr></thead>
                                                        <tbody>
                                                        <tr class="condition-clone-default" style="display:none;">
                                                            <td>
                                                                <select class="form-control filter-filed-name"></select>
                                                            </td>
                                                            <td>
                                                                <select class="form-control filter-filed-Operator"></select>
                                                            </td>
                                                            <td>
                                                                <input class="form-control filter-filed-value" name="value" type="text" />
                                                            </td>
                                                            <td>
                                                                <button type="button" class="btn btn-xs btn-warning" onclick="removeCondition(this)">
                                                                    <span class="glyphicon glyphicon-minus-sign"></span>
                                                                </button>
                                                            </td>
                                                        </tr>
                                                        <tr class="condition-item">
                                                            <td>
                                                                <select class="form-control filter-filed-name"></select>
                                                            </td>
                                                            <td>
                                                                <select class="form-control filter-filed-Operator"></select>
                                                            </td>
                                                            <td>
                                                                <input class="form-control filter-filed-value" name="value" type="text" />
                                                            </td>
                                                            <td>
                                                                <button type="button" class="btn btn-xs btn-info" onclick="addCondition(this)">
                                                                    <span class="glyphicon glyphicon-plus-sign"></span>
                                                                </button>
                                                            </td>
                                                        </tr>
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="hide" id="formulaSection">
                                            <div class="form-group col-sm-12">
                                                <label class="col-sm-2 control-label">公式</label>
                                                <div class="col-sm-10">
                                                    <textarea class="form-control" id="formula"></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </fieldset>
                                <div class="form-group col-sm-12 text-center" id="form-buttons">
                                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-saved"></span> 保存</button>
                                    <button type="reset" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> 重置</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>
            <nav class="navbar navbar-default navbar-fixed-bottom hide" role="navigation" id="body-footer">
                <div class="container">
                    <div class="navbar-form navbar-right" id="body-footer-content">
                    </div>
                </div>
            </nav>
        </div>
    </div>
</div>

<script src="/content/js/fetch.js"></script>
<script src="/content/js/filterdialog.js"></script>
<script src="/content/js/jquery.form.js"></script>
<script src="/content/js/jquery-validate/jquery.validate.min.js"></script>
<script src="/content/js/jquery-validate/localization/messages_zh.min.js"></script>
<script src="/content/js/xms.metadata.js"></script>
<script id="formvalidateAttr">
    $(function () {
        var model = $.urlParamObj(location.href);
        $('#entityid').val(model.entityid);
        //表单验证
        if (typeof $ !== undefined) {
            Xms.Web.Form($("#createattributeForm"), function (response) {
                if (response.IsSuccess) {
                    $('#settings').children().addClass('hide');
                }
                Xms.Web.Alert(response.IsSuccess, response.Content || response.ErrorMessage, function () {

                });
                if(response.IsSuccess) {
                    Xms.Web.Event.publish('refresh');
                    Xms.Web.Event.localStorageEvent.trigger('list_attribute_rebind');
                    Xms.Web.Event.publish('success&&&' + response.Extra.id, true);
                    $('#createattributeForm').trigger('formSuccess', {res: response});
                }
            }, true, function (e) {
                var checkName = CheckRepeat('optionsetname');
                var checkVal = CheckRepeat('optionsetvalue');
                var selThat = Xms.Web.SelectedValue($('#attributetypename'));
                if (!checkName || !checkVal) {
                    return false;
                }
            });
        }

    });

    "loadend"</script>

<script>
    $(function () {
        //字段类型
        $('#attributetypename').on("change", null, function (e) {
            $('#settings').children().addClass('hide');
            var type = $(this).val();
            if (type != '') {
                $(this).next('label[name="errorTip"]').remove();
                //$('#valueSetting').removeClass('hide');
            }
            else {
                //$('#valueSetting').addClass('hide');
                return;
            }
            $('#' + type + 'Setting').removeClass('hide');
            if (type == 'lookup') {
                //绑定引用实体
                loadEntities();
            }
        });
        $('#summaryentityid').on('change', null, function (e) {
            LoadSummaryAttributes();
        });
        $('#valuetype').on('change', null, function (e) {
            var vt = $(this).val();
            //var at = Xms.Web.SelectedValue($('#attributetypename'));
            $('#valueSection').children().addClass('hide');
            if (vt == 1) {
                $('#defaultSection').removeClass('hide');
            }
            else if (vt == 2) {
                $('#formulaSection').removeClass('hide');
            }
            else if (vt == 3) {
                LoadRelatedEntities();
                $('#summarySection').removeClass('hide');
            }
        });
        $('input[name=summaryfiltertype]').on('change', null, function (e) {
            var t = $(this).val();
            var $filterSection = $('#filterSection');
            if (t == 2) {
                $filterSection.removeClass('hide');
                /*加载字段*/
                var entityid = $('#entityid').val();
                var filters = Xms.Fetch.FilterExpression();
                filters.Conditions = [];
                var postData = {
                    entityid: entityid,
                    filter: filters
                }
                $filterSection.attr({'data-entityid': entityid});
                Xms.Web.Post('/filter/simple', postData, false, function (res) {
                    $filterSection.html(res);
                },false,false,false);
            } else {
                $filterSection.addClass('hide');
            }
        });
        //选项集
        Xms.Web.SingleCheckbox('#optionset-picklist', 'input[type=checkbox]', 'single', function (context) {
            console.log($(this))
            var hideIn = $(this).siblings("input[name='isselectedoption']");
            $("input[name='isselectedoption']").val('false');
            hideIn.val(true);
        });
        $('#optionset-type').bind("change", function () {
            var t = $(this).find('option:selected').val();
            if (t == 'checkbox') {
                Xms.Web.SingleCheckbox('#optionset-picklist', 'input[type=checkbox]', 'multi');
                $("input[type=checkbox]", '#optionset-picklist').unbind("click").bind("click", function (context) {
                    var hideIn = $(this).siblings("input[name='isselectedoption']");
                    hideIn.val($(this).prop("checked"));
                });
            }
            else {
                Xms.Web.SingleCheckbox('#optionset-picklist', 'input[type=checkbox]', 'single', function (context) {
                    var hideIn = $(this).siblings("input[name='isselectedoption']");
                    $("input[name='isselectedoption']").val('false');
                    hideIn.val(true);
                });
            }
        });
        //复选框设置为单选
        Xms.Web.SingleCheckbox('#bitSetting', 'input[type=checkbox]', 'single', function (context) {
            console.log($(this))
            var hideIn = $(this);//.siblings("input[name='isselectedoption'],input[name='bitisdefault']");
            $("input[type=checkbox]", '#bitSetting').val(false);
            hideIn.val(true);
        });
        //检查名称是否已存在
        $('#Name').bind('change', function () {
            var $this = $(this);
            var name = $this.val();
            if (name != '') {
                Xms.Web.Get('/api/schema/attribute/exists?entityid=' + $('#entityid').val() + '&name=' + name, function (response) {
                    $this.next().remove();
                    $this.parents('.form-group').removeClass('has-error');
                    if (response.IsSuccess) {
                        $this.after($('<div class="text-danger"><span class="glyphicon glyphicon-remove-sign"></span>' + LOC_ATTRIBUTE_NAME_EXISTS + '</div>'));
                        $this.parents('.form-group').addClass('has-error');
                    }
                });
            }
        });
        $('button[type="submit"]').off('click').on('click', function (e) {
            e.preventDefault();
            valueSetJson();
            $('form:first').submit();
        });

    });

    function checkOptionsData() {
        var flag = true;
        var $optionsetpicklist = $('#optionset-picklist');
        var $list = $optionsetpicklist.find('tbody>tr');
        var namelist = [];
        var valuelist = [];
        if ($list.length > 1) {
            $list.each(function () {
                var _name = $(this).find('input[name="optionsetname"]');
                var _value = $(this).find('input[name="optionsetvalue"]');
                if ($.inArray(_name, namelist) || $.inArray(_value, valuelist)) {
                    flag = false;
                    return false;
                }
            });
        }
        return flag;
    }

    //选项集-增加选项
    function addOption(id) {
        var $target = $("#" + id);
        var newRow = $target.find('tr:last').clone();
        newRow.find('input[type=text]').val('');
        newRow.find('input[type=checkbox]').prop('checked', false);
        $target.append(newRow);
    }
    //选项集-删除选项
    function removeOption(id, row) {
        var $target = $("#" + id);
        if ($(row).parents('tr').siblings().length > 0) {
            $(row).parents('tr').remove();
        }
        else {
            var newRow = $(row).parents('tr');
            newRow.find('input[type=text]').val('');
            newRow.find('input[type=checkbox]').prop('checked', false);
        }
    }
    //选项集-清空选项
    function clearOption(id) {
        var $target = $("#" + id);
        $target.find('tbody').find('tr:gt(0)').remove();
        var newRow = $target.find('tbody').find('tr:last');
        newRow.find('input[type=text]').val('');
        newRow.find('input[type=checkbox]').prop('checked', false);
    }
    //选项集-排序选项
    function moveOption(id, row, isup) {
        var $target = $("#" + id);
        var $this = $(row).parents('tr');
        if (isup == true && $this.prev().length > 0) {
            $this.insertBefore($this.prev());
        }
        else if (isup == false && $this.next().length > 0) {
            $this.insertAfter($this.next());
        }
    }
    //公共选项集or私有
    function selectOptionset(o) {
        var $this = $(o);
        if ($this.prop('checked') == true) {
            $('#optionset-commonarea').removeClass('hide');
            $('#optionset-privatearea').addClass('hide');
            loadOptionSet();
        }
        else {
            $('#optionset-privatearea').removeClass('hide');
            $('#optionset-commonarea').addClass('hide');
        }
    }
    //加载公共选项集
    function loadOptionSet() {
        var optionsetSelect = $('#optionset-common');
        optionsetSelect.empty();
        Xms.Schema.GetOptionsets({ ispublic: true, getall: true }, function (data) {
            //console.log(data);
            if (!data || data.length == 0) return;
            $(data).each(function (i, n) {
                optionsetSelect.append("<option value=\"" + n.optionsetid + "\">" + n.name + "</option>");
            });
        });
    }
    //加载引用实体
    function loadEntities() {
        var entitySelect = $('#lookup-entity');
        entitySelect.entitySelector({
        });
    }

    //检查是否有重复的值
    function CheckRepeat(classname) {
        var check = true;
        $('.' + classname).each(function (i, n) {
            var nVal = $(n).val();
            var ncheck = true;
            if (nVal == '') {
                return true;
            }
            $('.' + classname).each(function (ii, nn) {
                var nnVal = $(nn).val();
                if (nnVal == '') {
                    return true;
                }
                if (nVal == nnVal && i != ii) {
                    if ($(n).next('label[name="repeatTip"]').length == 0) {
                        $('<label name="repeatTip">' + LOC_ATTRIBUTE_OPTION_DUPLICATED + '</label>').insertAfter($(n));
                    }
                    ncheck = false;
                    check = false;
                    return false;
                }
            });
            if (ncheck == true) {
                $(n).next('label[name="repeatTip"]').remove();
            }
        });
        return check;
    }
    //加载汇总来源实体
    function LoadRelatedEntities() {
        var _target = $('#summaryentityid');
        var entityid = $('#entityid').val();
        Xms.Schema.GetEntityRelations(null, entityid, function (data) {
            if (!data || data.length == 0) return;
            //_target.append('<option value="">--请选择--</option>');
            var html = [];

            $(data).each(function (i, n) {
                html.push('<option data-relationshipname="' + n.name + '" data-referencingentityname="' + n.referencingentityname + '" value="' + n.referencingentityid + '">' + n.referencingentitylocalizedname + '(' + n.referencedentitylocalizedname + ')' + '</option>')

            });
            _target.html(html.join(''));
            _target.trigger('change');
        }, null, false);
    }
    //加载汇总来源字段
    function LoadSummaryAttributes() {
        var entityid = Xms.Web.SelectedValue($('#summaryentityid'));
        if (!entityid) return;
        var _target = $('#summaryfield');
        _target.empty();
        Xms.Schema.GetAttributes({ getall: true, entityid: entityid, attributetypename: ["int", "float", "money"] }, function (data) {
            if (!data || data.length == 0) return;
            var html = [];
            $(data).each(function (i, n) {
                html.push('<option value="' + n.attributeid + '" data-name="' + n.name + '" data-attributename="' + n.attributetypename + '">' + n.localizedname + '</option>')

            });
            _target.html(html.join(''));
        });
    }
    //设置值得JSON数据
    function valueSetJson() {
        var $value = $('#SummaryExpression');
        var $valuetype = $('#valuetype');
        if ($valuetype.val() == 0) {
            $value.val('');
        } else {
            se.aggregate = $('#summarytype').val();
            se.entityname = $('#summaryentityid option:selected').attr('data-referencingentityname');
            se.field = $('#summaryfield option:selected').attr('data-name');
            if ($('input[name="summaryfiltertype"]:checked').val() == 1) {
                se.filter = null;
            } else {
                setFiltersData();
                if ($('#filterConditions').val() != "") {
                    se.filter = JSON.parse(decodeURIComponent($('#filterConditions').val()));
                }
            }
            se.relationshipname = $('#summaryentityid option:selected').attr('data-relationshipname');
            console.log('过滤条件数据', se);
            $value.val('').val(JSON.stringify(se));
        }
    }
    function setFiltersData() {
        var filterConditions = $('#filterConditions');
        var $conditions = $('.condition-item');
        var filters = Xms.Fetch.FilterExpression();
        $conditions.each(function () {
            var item = Xms.Fetch.ConditionExpression();
            item.AttributeName = $(this).find('.filter-filed-name').val();
            item.Operator = $(this).find('.filter-filed-Operator').val();
            item.Values.push($(this).find('input[name="value"]').val());
            if ($(this).find('input[name="value"]').val() != "") {
                filters.Conditions.push(item);
            }
        });

        filterConditions.val(encodeURIComponent(JSON.stringify(filters)));
    }
</script>

</body>
</html>